using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using sbMembership.Library.Presenters;
using sbMembership.Library.Presenters.ViewInterfaces;
using sbMembership.Library.Domain;

namespace sbMembership.Web.Views
{
    public partial class ListRolesView : System.Web.UI.UserControl, IListRolesView
    {
        ListRolesPresenter presenter;

        public void AttachPresenter(ListRolesPresenter presenter)
        {
            this.presenter = presenter;
        }

        public string Message
        {
            set { lblMessage.Text = value; }
        }

        public List<sbRole> Roles
        {
            set
            {
                gvRoles.DataSource = value;
                gvRoles.DataBind();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAddRole_Click(object sender, EventArgs e)
        {
            presenter.LaunchAddRole();
        }

        protected void gvRoles_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

        protected void gvRoles_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int rowID = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow gr = gvRoles.Rows[rowID];
                string user = ((LinkButton)gr.Cells[0].Controls[0]).Text;
                presenter.DeleteRole(user);
            }
            if (e.CommandName == "Select")
            {
                int rowID = Int32.Parse(e.CommandArgument.ToString());
                GridViewRow gr = gvRoles.Rows[rowID];
                string roleName = ((LinkButton)gr.Cells[0].Controls[0]).Text;
                presenter.LaunchEditRole(roleName);
            }

        }
    }
}